﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.Reports.ReportPages
{
    public partial class DeptList_Page : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int typeid = _Request.GetInt("typeid", 0);          // 1盘源更进 2客源跟进 3待看提醒 4已带看 5新添盘源 6新添客源 7独家 8反签 9钥匙 10查看电话 11上传图片盘源 12上传图片数 13自看房源  
                int deptId = _Request.GetInt("deptid", 0);          // 部门ID                 

                bool isContainsSelf = false;                        //查询下级子部门时,是否包括自己                
                if (deptId <= 0)
                    deptId = _Convert.ToInt(_Utility.GetInfoBySession().m_sDeptID, 0);
                else
                    isContainsSelf = true;

                if (_Request.GetInt("isContainsSelf", 0) > 0)       // 前台传过来的值，如果为1，表示不包括自己
                    isContainsSelf = false;

                string startdate = _Request.GetString("addDate1", DateTime.Today.ToString("yyyy-MM-dd"));
                string enddate = _Request.GetString("addDate2", DateTime.Today.ToString("yyyy-MM-dd"));

                string condition = " where 1=1 ";
                string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(deptId.ToString(), isContainsSelf);

                if (deptId > 0)
                    condition += " and deptid in(" + deptIdList + ")";

            


                if (startdate != "" && enddate != "")
                    // condition += " and countDate >= '" + startdate + "' and countDate <= '" + enddate + "'";
                    condition += " and DATEDIFF(dd, countDate, '" + startdate + "') <= 0 and DATEDIFF(dd, countDate, '" + enddate + "') >= 0";

                DataTable dt = ZLDC.Topo.BLL.Estate.ReportBLL.p_report_dept_list(1, condition);
                                
                //为报表浏览器指定报表文件                
                this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(GetRdlcFilePathByTypeID(typeid));
                
                // 梆定数据集
                this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DeptList_Data_t_DeptList", dt));

                //显示报表
                this.ReportViewer1.LocalReport.Refresh();
            }
        }        
        
        /// <summary>
        /// 根据类型动态获取rdlc文件路径
        /// </summary>
        /// <param name="typeid"> 1盘源更进 2客源跟进 3待看提醒 4已带看 5新添盘源 6新添客源 7独家 8反签 9钥匙 10查看电话 11上传图片盘源 12上传图片数 13自看房源 </param>
        /// <returns></returns>
        public string GetRdlcFilePathByTypeID(int typeid)
        {
            string rdlcFilePath = "../ReportFiles/DeptList_Info_HFollow.rdlc";

            if (typeid == 1)
                rdlcFilePath = "../ReportFiles/DeptList_Info_HFollow.rdlc";
            else if (typeid == 2)
                rdlcFilePath = "../ReportFiles/DeptList_Info_CFollow.rdlc";
            else if (typeid == 3)
                rdlcFilePath = "../ReportFiles/DeptList_Info_Look.rdlc";
            else if (typeid == 4)
                rdlcFilePath = "../ReportFiles/DeptList_Info_Looked.rdlc";
            else if (typeid == 5)
                rdlcFilePath = "../ReportFiles/DeptList_Info_NewHousing.rdlc";
            else if (typeid == 6)
                rdlcFilePath = "../ReportFiles/DeptList_Info_NewCustomer.rdlc";
            else if (typeid == 7)
                rdlcFilePath = "../ReportFiles/DeptList_Info_Only.rdlc";
            else if (typeid == 8)
                rdlcFilePath = "../ReportFiles/DeptList_Info_Versa.rdlc";
            else if (typeid == 9)
                rdlcFilePath = "../ReportFiles/DeptList_Info_Key.rdlc";
            else if (typeid == 10)
                rdlcFilePath = "../ReportFiles/DeptList_Info_TelPhone.rdlc";
            else if (typeid == 11)
                rdlcFilePath = "../ReportFiles/DeptList_Info_HasPhoto.rdlc";
            else if (typeid == 12)
                rdlcFilePath = "../ReportFiles/DeptList_Info_Photo.rdlc";
            else if (typeid == 13)
                rdlcFilePath = "../ReportFiles/DeptList_Info_Self.rdlc";
            else if (typeid == 14)
                rdlcFilePath = "../ReportFiles/DeptUserList_Info_NewHousing.rdlc";
            else if (typeid == 15)
                rdlcFilePath = "../ReportFiles/DeptUserList_Info_NewCustomer.rdlc";

            return rdlcFilePath;
        }
    }
}
